package cn.com.dhcc.turbo.dao.exch;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.dao.AbstractCrudDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.handler.modulehandler.WhereCondition;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.pub.core.consts.AppConst;
import cn.com.dhcc.turbo.entity.registry.FtpUser;

@Repository
public class FtpUserDao extends AbstractCrudDao<FtpUser> {
    @SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.TURBO);

    public List<FtpUser> getAllFtpUser() throws DaoException {
        String msg = "";
        try {
            WhereCondition whereCondition = new WhereCondition().where().eq("enableflag", 1).and().notEq("userid", AppConst.EMBFTP.EMBFTP_ADMIN_USERID);
            return list(whereCondition);
        } catch (DaoException e) {
            msg = "获取FtpUser用户列表失败";
            logger.error("获取FtpUser用户列表失败", e);
            throw new DaoException(msg, e);
        }

    }
    public FtpUser getFtpadmin() throws DaoException {
        String msg = "";
        try {
            return  this.get(AppConst.EMBFTP.EMBFTP_ADMIN_USERID);
        } catch (DaoException e) {
            msg = "获取FtpUser用户列表失败";
            logger.error("获取FtpUser用户列表失败", e);
            throw new DaoException(msg, e);
        }
    }

    public boolean addFtpUser(FtpUser ftpUser) throws DaoException {
        String msg = "";
        try {
            return 1 == CM.getDao().insertModule("添加ftp用户", ftpUser);
        } catch (DaoException e) {
            msg = "添加FtpUser用户失败";
            logger.error("添加FtpUser用户失败", e);
            throw new DaoException(msg, e);
        }
    }

}
